﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using BCCommon;
using BCDto.OA.PageBusiness.PageBusinessMappingDepartment;
using BCService.OA.PageBusiness.PageBusinessMappingDepartment;
using BCService.Utils;
using BlackCoffeeRESTful.Configs;

namespace BlackCoffeeRESTful.Controllers.Management.OA.PageBusiness.PageBusinessMappingDepartment
{
    /// <summary>
    /// OA系统页面业务映射部门
    /// </summary>
    [ApiExplorerSettings(GroupName = "OAAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class PageBusinessMappingDepartmentController : ManagementBaseController
    {
        private readonly IPageBusinessMappingDepartmentService pageBusinessMappingDepartmentService;

        public PageBusinessMappingDepartmentController(IPageBusinessMappingDepartmentService pageBusinessMappingDepartmentService)
        {
            this.pageBusinessMappingDepartmentService = pageBusinessMappingDepartmentService;
        }

        #region 添加OA系统页面业务映射部门
        /// <summary>
        ///  添加OA系统页面业务映射部门
        /// </summary>
        /// <param name="requestDto">OA系统页面业务映射部门信息</param>
        /// <response code="201">添加OA系统页面业务映射部门成功</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加OA系统页面业务映射部门")]
        [ProducesResponseType(typeof(PageBusinessMappingDepartmentDto), 201)]
        public IActionResult Post([FromBody]PageBusinessMappingDepartmentRequestDto requestDto)
        {
            var result = this.pageBusinessMappingDepartmentService.Add(requestDto);
            return this.Created(string.Format("api/v1/sim/PageBusinessMappingDepartment/{0}", result.PageBusinessMappingDepartmentId), result);
        }
        #endregion

        #region 修改OA系统页面业务映射部门
        /// <summary>
        ///  修改OA系统页面业务映射部门
        /// </summary>
        /// <param name="pageBusinessMappingDepartmentId">OA系统页面业务映射部门Id</param>
        /// <param name="requestDto">OA系统页面业务映射部门信息</param>
        /// <response code="200">修改OA系统页面业务映射部门成功</response>
        /// <returns></returns>
        [HttpPut("{page_business_mapping_department_id}")]
        [Log("修改OA系统页面业务映射部门")]
        [ProducesResponseType(typeof(PageBusinessMappingDepartmentDto), 200)]
        public IActionResult Post([FromRoute(Name = "page_business_mapping_department_id")]long pageBusinessMappingDepartmentId, [FromBody]PageBusinessMappingDepartmentRequestDto requestDto)
        {
            PageBusinessMappingDepartmentPutDto putDto = requestDto.As<PageBusinessMappingDepartmentPutDto>();
            putDto.PageBusinessMappingDepartmentId = pageBusinessMappingDepartmentId;
            return this.Ok(this.pageBusinessMappingDepartmentService.Update(putDto));
        }
        #endregion

        #region 删除OA系统页面业务映射部门
        /// <summary>
        ///  删除OA系统页面业务映射部门
        /// </summary>
        /// <param name="pageBusinessMappingDepartmentId">OA系统页面业务映射部门Id</param>
        /// <response code="204">删除OA系统页面业务映射部门成功</response>
        /// <returns></returns>
        [HttpDelete("{page_business_mapping_department_id}")]
        [Log("删除OA系统页面业务映射部门")]
        public IActionResult Delete([FromRoute(Name = "page_business_mapping_department_id")]long pageBusinessMappingDepartmentId)
        {
            this.pageBusinessMappingDepartmentService.Delete(pageBusinessMappingDepartmentId);
            return this.NoContent();
        }
        #endregion

        #region 获取OA系统页面业务映射部门
        /// <summary>
        ///  获取OA系统页面业务映射部门
        /// </summary>
        /// <param name="pageBusinessMappingDepartmentId">OA系统页面业务映射部门Id</param>
        /// <response code="200">获取OA系统页面业务映射部门</response>
        /// <returns></returns>
        [HttpGet("{page_business_mapping_department_id}")]
        [ProducesResponseType(typeof(PageBusinessMappingDepartmentDto), 200)]
        public IActionResult Get([FromRoute(Name = "page_business_mapping_department_id")]long pageBusinessMappingDepartmentId)
        {
            return this.Ok(this.pageBusinessMappingDepartmentService.GetEntity(pageBusinessMappingDepartmentId));
        }
        #endregion

        #region 获取OA系统页面业务映射部门列表
        /// <summary>
        ///  获取OA系统页面业务映射部门列表
        /// </summary>
        /// <response code="200">获取OA系统页面业务映射部门列表</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(PageBusinessMappingDepartmentDto), 200)]
        public IActionResult Get()
        {
            return this.Ok(this.pageBusinessMappingDepartmentService.GetList(this.Admin.CompanyId));
        }
        #endregion

        #region 获取OA系统页面业务映射部门（分页）
        /// <summary>
        ///  获取OA系统页面业务映射部门（分页）
        /// </summary>
        /// <param name="pageBusinessConfigId">页面业务配置Id</param>
        /// <param name="pageBusinessName">页面业务名称</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="pageIndex">以 1 起始的页码 (默认 1)。</param>
        /// <param name="pageSize">每页要显示的行数 (默认 10)。</param>
        /// <response code="200">获取OA系统页面业务映射部门（分页）</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<PageBusinessMappingDepartmentDto>), 200)]
        public IActionResult Query([FromQuery(Name = "page_business_config_id")]long pageBusinessConfigId,
            [FromQuery(Name = "page_business_name")]string pageBusinessName,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            int pageIndex = 1,
            int pageSize = 10)
        {
            return this.Ok(this.pageBusinessMappingDepartmentService.Query(this.Admin.CompanyId, pageBusinessConfigId,pageBusinessName, start,end,pageIndex, pageSize));
        }
        #endregion

    }
}
